package com.jshoperxms.components.wechat.check;

import com.jshoperxms.components.wechat.WxConfig;
import com.jshoperxms.components.wechat.WxErrorBean;
import com.jshoperxms.components.wechat.WxSessionKeyBean;
import com.jshoperxms.components.wechat.WxTokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by sdywcd on 2019/10/15.
 * Des:
 */
@Component
public class WxMediaCheckController {

    @Autowired
    private WxTokenUtils wxTokenUtils;
    @Autowired
    private RestTemplate restTemplate;


    /**
     * 检查消息文本内容是否合规
     * @param content
     * @return
     */
    public Map<String,Object> msgSecCheck(String content){
        Map<String,Object>maps=new HashMap<>();
        String accessToken=wxTokenUtils.getToken();
        String url="https://api.weixin.qq.com/wxa/msg_sec_check?access_token="+accessToken;
        ResponseEntity<WxErrorBean> tkb=restTemplate.postForEntity(url,content,WxErrorBean.class);
        if (tkb.getStatusCode().equals(HttpStatus.OK)){
            WxErrorBean wxErrorBean=tkb.getBody();
            maps.put("code",wxErrorBean.getErrcode());
            maps.put("msg",wxErrorBean.getErrmsg());
        }
        return maps;
    }

  

}
